package com.linghu.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

@Service
public class EventService {

    private final ObjectMapper objectMapper;

    public EventService(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    public void handleEvent(String event, JsonNode content) {
        try {
            switch (event) {
                case "verify_webhook":
                    // 已在控制器中处理，可以留空或记录日志
                    break;
                case "order_message_notification":
                    // 假设 content 包含订单状态信息
                    String orderStatus = content.path("order_status").asText();
                    if ("预约上门".equals(orderStatus)) {
                        // 执行预约上门相关的逻辑，例如发送通知、更新数据库等
                        System.out.println("处理预约上门事件: " + content.toString());
                        // 你的业务逻辑
                    } else {
                        // 处理其他订单状态
                        System.out.println("处理其他订单状态: " + content.toString());
                    }
                    break;
                // 添加其他事件处理
                default:
                    System.out.println("收到未处理的事件类型: " + event);
            }
        } catch (Exception e) {
            System.err.println("处理事件时出错: " + e.getMessage());
        }
    }
}